package com.wlyuan.open.remote.facade;

import com.alibaba.fastjson.JSON;
import com.wlyuan.area.api.AreaParseService;
import com.wlyuan.area.constants.AnalyzerStatusEnum;
import com.wlyuan.open.remote.facade.translator.AddressTranslator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author lijing
 * @description
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class AreaFacade {
    @DubboReference(check = false)
    private AreaParseService areaParseService;

    public Address getArea(AddressDTO address) {
        logger.info("省市区参数：{}", JSON.toJSON(address));
        var translator = AddressTranslator.assemblerParse(address);
        translator.setCheck(false);
        logger.info("省市区处理市辖区参数：{}", JSON.toJSON(translator));
        var result = areaParseService.parse(translator);
        logger.info("省市区处理结果：{}", JSON.toJSON(result));
        return AnalyzerStatusEnum.SUCCESS.equals(result.getStatus()) ? AddressTranslator.assemblerParse(result.getArea()) : null;
    }
}
